package com.ruoyi.web.controller.gallery;

import java.util.List;

import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.domain.gallery.GalleryComment;
import com.ruoyi.system.service.gallery.GalleryCommentService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 图库评论Controller
 * 
 * @author 张少丛
 * @date 2020-12-02
 */
@RestController
@RequestMapping("/gallery/comment")
public class GalleryCommentController extends BaseController
{
    @Autowired
    private GalleryCommentService galleryCommentService;

    @Autowired
    private TokenService tokenService;

    /**
     * 查询图库评论列表
     */
    @PreAuthorize("@ss.hasPermi('gallery:comment:list')")
    @GetMapping("/list")
    public TableDataInfo list(GalleryComment galleryComment)
    {
        startPage();
        // 获取登录用户ID
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        Long userId = loginUser.getUser().getUserId();
        List<GalleryComment> list = galleryCommentService.selectGalleryCommentList(galleryComment,userId);
        return getDataTable(list);
    }

    /**
     * 导出图库评论列表
     */
    @PreAuthorize("@ss.hasPermi('gallery:comment:export')")
    @Log(title = "图库评论", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(GalleryComment galleryComment)
    {
        // 获取登录用户ID
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        Long userId = loginUser.getUser().getUserId();
        List<GalleryComment> list = galleryCommentService.selectGalleryCommentList(galleryComment,userId);
        ExcelUtil<GalleryComment> util = new ExcelUtil<GalleryComment>(GalleryComment.class);
        return util.exportExcel(list, "comment");
    }

    /**
     * 获取图库评论详细信息
     */
    @PreAuthorize("@ss.hasPermi('gallery:comment:query')")
    @GetMapping(value = "/{galleryCommentId}")
    public AjaxResult getInfo(@PathVariable("galleryCommentId") Long galleryCommentId)
    {
        return AjaxResult.success(galleryCommentService.selectGalleryCommentById(galleryCommentId));
    }

    /**
     * 新增图库评论
     */
    @PreAuthorize("@ss.hasPermi('gallery:comment:add')")
    @Log(title = "图库评论", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GalleryComment galleryComment)
    {
        return toAjax(galleryCommentService.insertGalleryComment(galleryComment));
    }

    /**
     * 修改图库评论
     */
    @PreAuthorize("@ss.hasPermi('gallery:comment:edit')")
    @Log(title = "图库评论", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GalleryComment galleryComment)
    {
        return toAjax(galleryCommentService.updateGalleryComment(galleryComment));
    }

    /**
     * 删除图库评论
     */
    @PreAuthorize("@ss.hasPermi('gallery:comment:remove')")
    @Log(title = "图库评论", businessType = BusinessType.DELETE)
	@DeleteMapping("/{galleryCommentIds}")
    public AjaxResult remove(@PathVariable Long[] galleryCommentIds)
    {
        return toAjax(galleryCommentService.deleteGalleryCommentByIds(galleryCommentIds));
    }
}
